#ifndef _NAND_DEVICE_H
#define _NAND_DEVICE_H

//#define DEBUG_NAND

#include "NAND_device_if.h"

const unsigned DEFAULT_ERASE_BUSY_CYCLE		= 5000; // arbitrary value
const unsigned DEFAULT_PROGRAM_BUSY_CYCLE	= 2377;
const unsigned DEFAULT_READ_BUSY_CYCLE		= 1000;

const unsigned DEFAULT_PAGE_PER_BLOCK	= 64;
const unsigned DEFAULT_BLOCK_PER_PLANE	= 1024;

class NAND_device
: public sc_module
, public NAND_device_if
{
public :
	sc_in_clk	CLK;
	sc_in<bool> RSTn;

	const bool
	NAND_read_R_B() const;
	
	const byte
	NAND_read() const;
	
	void
	NAND_write(byte	DATA_IO);

	SC_HAS_PROCESS(NAND_device);

	NAND_device(sc_module_name	name_);
	
	~NAND_device();

protected:
	byte FLASH_Array[NAND_PAGE_SIZE*DEFAULT_PAGE_PER_BLOCK*DEFAULT_BLOCK_PER_PLANE/2]; // 128MBytes(1Gbits)

	byte			DATA_IO;
	bool			R_B;

	NAND_state_t	current_state;

	byte			cmd;
	byte			col_addr0;
	byte			col_addr1;
	byte			row_addr0;
	byte			row_addr1;
	unsigned		flash_addr;
	unsigned		DATA_cnt;
	unsigned		BUSY_cnt_program;
	unsigned		BUSY_cnt_read;
	unsigned		BUSY_cnt_erase;

	void
	flash_addr_gen();

	void
	FLASH_FSM_process();
};

#endif
